<template>
  <div class="todo">
    <input type="checkbox" :checked="todo.isChecked" @change="changeId(todo.id)">
    <span>{{todo.name}}</span>
    <span @click="deleteThisTodo(todo.id)" class="delBtn">删除任务</span>
  </div>
</template>

<script>
import pubsub from 'pubsub-js'

export default {
  name: 'MyTodo',
  props: ['todo'],
  methods: {
    changeId (id) {
      // this.$bus.$emit('changeStatusRecieveId', id)
      pubsub.publish('changeStatusRecieveId', id)
    },
    deleteThisTodo (id) {
      // this.$bus.$emit('deleteTodo', id)
      pubsub.publish('deleteTodo', id)
    }
  },
}
</script>

<style scoped>
.todo {
  position: relative;
  width: 400px;
  height: 40px;
  border: 1px solid #ccc;
  line-height: 40px;
}
.todo:hover {
  background-color: #ccc;
}
.todo:hover .delBtn {
  display: block;
}
span {
  padding-left: 5px;
}
.delBtn {
  position: absolute;
  top: 8px;
  right: 3px;
  height: 25px;
  background-color: red;
  color: #fff;
  line-height: 25px;
  border-radius: 5px;
  display: none;
  cursor: pointer;
}
</style>
    